package cz.fit.vutbr.pis2012.augeaswh.control.ekonom.stock_types;

import java.io.Serializable;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

import org.richfaces.component.SortOrder;

@ManagedBean
@SessionScoped
public class StockTypesSortingBean implements Serializable {
	
	private static final long serialVersionUID = 9125973855028434484L;
	private SortOrder nameOrder = SortOrder.unsorted;
    private SortOrder procuctClassOrder = SortOrder.unsorted;
    private SortOrder priceOrder = SortOrder.unsorted;
    private SortOrder amountOrder = SortOrder.unsorted;
        
    public void sortByName() {
        procuctClassOrder = SortOrder.unsorted;
        priceOrder = SortOrder.unsorted;
        setAmountOrder(SortOrder.unsorted);
        
        if (nameOrder.equals(SortOrder.ascending)) {
            setNameOrder(SortOrder.descending);
        } else {
        	setNameOrder(SortOrder.ascending);
        }
    }
    
    public void sortByProductClass() {
        nameOrder = SortOrder.unsorted;
        priceOrder = SortOrder.unsorted;
        setAmountOrder(SortOrder.unsorted);
                
        if (procuctClassOrder.equals(SortOrder.ascending)) {
            setProductClassOrder(SortOrder.descending);
        } else {
        	setProductClassOrder(SortOrder.ascending);
        }
    }
    
    public void sortByPrice() {
        nameOrder = SortOrder.unsorted;
        procuctClassOrder = SortOrder.unsorted;
        setAmountOrder(SortOrder.unsorted);
                
        if (priceOrder.equals(SortOrder.ascending)) {
            setPriceOrder(SortOrder.descending);
        } else {
        	setPriceOrder(SortOrder.ascending);
        }
    }
    
    public void sortByAmount() {
        nameOrder = SortOrder.unsorted;
        procuctClassOrder = SortOrder.unsorted;
        priceOrder = SortOrder.unsorted;
         
        if (amountOrder.equals(SortOrder.ascending)) {
        	setAmountOrder(SortOrder.descending);
        } else {
        	setAmountOrder(SortOrder.ascending);
        }
    }
    
	public SortOrder getNameOrder() {
		return nameOrder;
	}

	public void setNameOrder(SortOrder nameOrder) {
		this.nameOrder = nameOrder;
	}

	public SortOrder getProductClassOrder() {
		return procuctClassOrder;
	}

	public void setProductClassOrder(SortOrder productClassOrder) {
		this.procuctClassOrder = productClassOrder;
	}

	public SortOrder getPriceOrder() {
		return priceOrder;
	}

	public void setPriceOrder(SortOrder priceOrder) {
		this.priceOrder = priceOrder;
	}

	public SortOrder getAmountOrder() {
		return amountOrder;
	}

	public void setAmountOrder(SortOrder amountOrder) {
		this.amountOrder = amountOrder;
	}
}
